import { http } from '../utils/request'

// 订单基础操作API
export const orderAPI = {
  // 获取订单列表
getOrders(params) {
  console.log('API调用参数:', params) // 调试信息
  return http.get('/order/orders/', params)
},

  // 获取订单详情
  getOrderDetail(id) {
    return http.get(`/order/orders/${id}/`)
  },

  // 创建订单（使用路线规划功能）
  createOrder(data) {
    return http.post('/order/create/', data)
  },

  // 更新订单
  updateOrder(id, data) {
    return http.put(`/order/orders/${id}/`, data)
  },

  // 删除订单
  deleteOrder(id) {
    return http.delete(`/order/orders/${id}/`)
  },

  // 取消订单
  cancelOrder(id, data) {
    return http.post(`/order/orders/${id}/cancel/`, data)
  },

  // 获取订单状态日志
  getOrderStatusLogs(id) {
    return http.get(`/order/orders/${id}/status_logs/`)
  }
}

// 乘客订单API
export const passengerOrderAPI = {
  // 获取乘客订单列表
  getPassengerOrders(passengerId) {
    return http.get('/order/passenger/orders/', { passenger_id: passengerId })
  }
}

// 司机订单API
export const driverOrderAPI = {
  // 获取司机订单列表
  getDriverOrders(driverId) {
    return http.get('/order/driver/orders/', { driver_id: driverId })
  },

  // 司机接单
  acceptOrder(data) {
    return http.post('/order/driver/orders/accept/', data)
  },

  // 手动确认支付成功（沙箱环境用）
  manualConfirmPayment(orderNumber) {
    return http.post('/order/manual/payment/success/', {
      order_number: orderNumber
    })
  },

  // 获取司机今日统计数据
  getDriverDailyStats(driverId) {
    return http.get('/order/driver/daily-stats/', { driver_id: driverId })
  }
}

// 评论提交API（新版本，支持AI审核）
export const commentAPI = {
  // 提交评论（支持图片上传）
  submitComment(data) {
    return http.post('/order/comment/submit/', data, {
      headers: {
        'Content-Type': 'multipart/form-data'
      }
    })
  },

  // 获取评论列表
  getComments(params = {}) {
    return http.get('/order/comment/crud/', params)
  },

  // 获取评论详情
  getCommentDetail(id) {
    return http.get(`/order/comment/crud/${id}/`)
  },

  // 更新评论
  updateComment(id, data) {
    return http.put(`/order/comment/crud/${id}/`, data)
  },

  // 删除评论
  deleteComment(id) {
    return http.delete(`/order/comment/crud/${id}/`)
  },

  // 获取司机评论列表（只显示审核通过的）
  getDriverComments(driverId) {
    return http.get('/order/comment/driver-list/', { driver_id: driverId })
  },

  // 查询评论审核状态
  getCommentAuditStatus(commentId) {
    return http.get('/order/comment/audit-status/', { comment_id: commentId })
  },

  // 获取AI审核任务状态
  getAuditTaskStatus() {
    return http.get('/order/comment/audit-task/')
  },

  // 启动/停止AI审核工作器
  controlAuditWorker(action) {
    return http.post('/order/comment/audit-task/', { action })
  },

  // 获取AI审核日志
  getAuditLogs(params = {}) {
    return http.get('/order/comment/audit-logs/', params)
  }
}

// 订单评价API（旧版本，保留兼容性）
export const orderRatingAPI = {
  // 获取评价列表
  getRatings() {
    return http.get('/order/ratings/')
  },

  // 获取评价详情
  getRatingDetail(id) {
    return http.get(`/order/ratings/${id}/`)
  },

  // 创建评价
  createRating(data) {
    return http.post('/order/ratings/', data)
  },

  // 删除评价
  deleteRating(id) {
    return http.delete(`/order/ratings/${id}/`)
  }
}

// 订单投诉API
export const orderComplaintAPI = {
  // 获取投诉列表
  getComplaints(params = {}) {
    return http.get('/order/complaints/', params)
  },

  // 获取投诉详情
  getComplaintDetail(id) {
    return http.get(`/order/complaints/${id}/`)
  },

  // 创建投诉
  createComplaint(data) {
    return http.post('/order/complaints/', data)
  },

  // 删除投诉
  deleteComplaint(id) {
    return http.delete(`/order/complaints/${id}/`)
  },

  // 更新投诉
  updateComplaint(id, data) {
    return http.put(`/order/complaints/${id}/`, data)
  }
}

// 额外费用API
export const orderExtraFeeAPI = {
  // 获取额外费用列表
  getExtraFees(params = {}) {
    return http.get('/order/extra-fees/', params)
  },

  // 获取额外费用详情
  getExtraFeeDetail(id) {
    return http.get(`/order/extra-fees/${id}/`)
  },

  // 创建额外费用
  createExtraFee(data) {
    return http.post('/order/extra-fees/', data)
  },

  // 更新额外费用
  updateExtraFee(id, data) {
    return http.put(`/order/extra-fees/${id}/`, data)
  }
}

// 支付相关API
export const paymentAPI = {
  // 生成支付链接
  generatePayUrl(orderId) {
    return http.post(`/order/pay/${orderId}/`)
  }
} 